package com.test.learnkotlin.widget

import android.content.Context
import android.view.KeyEvent
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import android.widget.LinearLayout
import com.test.learnkotlin.R
import com.test.learnkotlin.bean.BaseInfoType
import com.test.learnkotlin.utils.LogUitls

class EditItem(context: Context): LinearLayout(context), PeopleDataInterface {

//    constructor(context: Context?) : super(context)
//
//    constructor(context: Context?, attributeSet: AttributeSet) : super(context, attributeSet)
//
//    constructor(context: Context?, attributeSet: AttributeSet, defStyleAttr: Int) : super(context, attributeSet, defStyleAttr)
//
//    constructor(context: Context?, attributeSet: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attributeSet, defStyleAttr, defStyleRes)

    var et_item_value: EditText



    init {
        val view = inflate(context, R.layout.item_edit, this)
        et_item_value = view.findViewById(R.id.et_item_value)
        et_item_value.isSingleLine = true
        et_item_value.imeOptions = EditorInfo.IME_ACTION_DONE
        et_item_value.setOnKeyListener { v, keyCode, event ->
            LogUitls.i("et_item_value 键盘事件回调")
            if (keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_UP) {
                LogUitls.i("et_item_value 回车键")
            }

            false
        }
    }

    override fun setItemData(baseInfoType: BaseInfoType) {
        et_item_value.setHint(baseInfoType.name)
    }

    override fun getSelectValueItemData(): String? = et_item_value.text.toString()
}